<?php

namespace Admin\Controller;





class PictureCatController extends BaseController {
    //图片分类显示
    public function lst(){
       
            $Picture_cat = D('Picture_cat');
            $count = $Picture_cat->count();
            $Page = new \Think\Page($count,20);
            $show = $Page->show();
            if (I('search')==''){
                $Pic = $Picture_cat->order('createtime')->limit($Page->firstRow.','.$Page->listRows)->select();
                $Pic1 = $Picture_cat->list_level($Pic);
                
                $this->assign('picture_cat',$Pic1);
                $this->assign('page',$show);
            }else {
                $search =trim(I('search'));
                $map['name']=array('like',"%$search%");
                $map['tags'] = array('like',"%$search%");
                $map['_logic'] = 'or';
                $Pic = $Picture_cat->where($map)->order('createtime desc')->limit($Page->firstRow.','.$Page->listRows)->select();
                $Pic1 = $Picture_cat->list_level($Pic);
                $this->assign('picture_cat',$Pic1);
                $this->assign('page',$show);
            }
            $this->display();
        
    }
    
    
    //图片分类添加
    public function ad(){
       
            $Picture_cat = D('Picture_cat');
            
            $parent =$Picture_cat->all();
           
            if (IS_POST){
                $data = array(
                    'name' => I('name'), 
                    'tags' => I('tags'),
                    'state' => I('state'),
                    'pid'=>I('pid'),
                    'createtime' => time(),
                );
                if ($Picture_cat->create($data)){
                    if ($Picture_cat->add()){
                        $this->success('新增成功',U('lst'));
                    }else {
                        $this->error('新增失败！');
                    }
                }else {
                    $this->error($Picture_cat->getError());
                }
                return ;
            }   

            $this->assign('parent',$parent);
            $this->display();
       
    }

    
    
    
    public function edt($id){
        
            $Picture_cat = D('Picture_cat');
            $Pic=$Picture_cat->find($id);
            
            $parent =$Picture_cat->all();
            $this->assign('parent',$parent);
            $this->assign('picture_cat',$Pic);
            if (IS_POST){
                $data =array(
                    'id'=>I('id'),
                    'name'=>I('name'),
                    'tags'=>I('tags'),
                    'state'=>I('state'),
                    'pid'=>I('pid'),
                    'createtime'=>time(),
                );
                if ($Picture_cat->create($data)){
                    if ($Picture_cat->save()){
                        $this->success('修改成功',U('lst'));
                    }else {
                        $this->error('修改失败！');
                    }
                }else {
                    $this->error($Picture_cat->getError());
                }
                
                return ;
            }
            
            
            $this->display();
        
        
    } 
    
    
    
    //图片分类单删除
    public function del($id){
       
            $Picture_cat =D('Picture_cat');
            if ($Picture_cat->delete($id)){
                $this->success('删除成功！',U('lst'));
            }else {
                $this->error('删除失败');
            }
        

    }
    //全部删除
    public function del_both(){
       
            $del_both = I('del_both');
            if ($del_both!==""){
                $del_id =implode(',', $del_both);
                $Picture_cat =D('Picture_cat');
                if ($Picture_cat->delete($del_id)){
                    $this->success('删除成功！',U('lst'));
                }else {
                    $this->error('删除失败');
                }
            }
     
        
    }

   
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
}